home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C08 QuickTime Music / P02 Play Scale / PlayScale.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  2.1 KB  |  95 lines  |  [TEXT/KAHL]

  1.  
  2. //____________________________________________________________
  3. //    PlayScale.c
  4. //
  5. //    Copyright © Dan Parks Sydow, 1995
  6. //    From the book:
  7. //    "Graphics and Sound Programming Techniques for the Mac",
  8. //    M&T Books, 1995
  9.  
  10.  
  11. //____________________________________________________________
  12.  
  13. #include <QuickTimeComponents.h>
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void  InitializeToolbox( void );
  19. void  InitializeInstrument( void );
  20. void  PlayMusicFromNoteChannel( void );
  21.  
  22.  
  23. //____________________________________________________________
  24.  
  25. NoteAllocator    gNoteAllocatorComp;
  26. ToneDescription  gToneDesc;
  27.  
  28.  
  29. //____________________________________________________________
  30.  
  31. void  main( void )
  32. {
  33.    InitializeToolbox();
  34.  
  35.    InitializeInstrument();
  36.  
  37.    PlayMusicFromNoteChannel();
  38. }
  39.  
  40.  
  41. //____________________________________________________________
  42.  
  43. void InitializeInstrument( void )
  44. {
  45.    gNoteAllocatorComp = OpenDefaultComponent( kNoteAllocatorType, 0 );
  46.  
  47.    gToneDesc.synthesizerType = 0;
  48.    gToneDesc.synthesizerName[0] = 0;
  49.    gToneDesc.instrumentName[0] = 0;
  50.    gToneDesc.instrumentNumber = 1;
  51.    gToneDesc.gmNumber = 1;
  52. }
  53.  
  54.  
  55. //____________________________________________________________
  56.  
  57. void  PlayMusicFromNoteChannel( void )
  58. {
  59.    NoteRequest     theNoteRequest;
  60.    NoteChannel     theNoteChannel;
  61.    short           thePitch;
  62.    ComponentResult theError;
  63.    long            theLong;
  64.  
  65.    theNoteRequest.polyphony = 4;
  66.    theNoteRequest.typicalPolyphony = 0x00010000;
  67.    theNoteRequest.tone = gToneDesc;
  68.  
  69.    theError = NANewNoteChannel( gNoteAllocatorComp, &theNoteRequest, &theNoteChannel );
  70.  
  71.    for ( thePitch = 36; thePitch <= 96; thePitch++ )
  72.    {
  73.       NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 127 );
  74.       Delay( 10, &theLong );
  75.       NAPlayNote( gNoteAllocatorComp, theNoteChannel, thePitch, 0 );
  76.    }
  77.  
  78.    theError = NADisposeNoteChannel( gNoteAllocatorComp, theNoteChannel );
  79. }
  80.  
  81.  
  82. //____________________________________________________________
  83.  
  84. void  InitializeToolbox( void )
  85. {
  86.    InitGraf( &qd.thePort );
  87.    InitFonts();
  88.    InitWindows();
  89.    InitMenus();
  90.    TEInit();
  91.    InitDialogs( 0L );
  92.    FlushEvents( everyEvent, 0 );
  93.    InitCursor();
  94. }
  95.